package com.example.hetingting

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class SecActivity : AppCompatActivity() {

    private lateinit var db: AppDatabase
    private lateinit var historyDao: HistoryDao
    private lateinit var recyclerView: RecyclerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_sec)

        db = AppDatabase.getDatabase(this)
        historyDao = db.historyDao()
        recyclerView = findViewById(R.id.recyclerView)

        loadHistory()
    }

    private fun loadHistory() {
        CoroutineScope(Dispatchers.IO).launch {
            val historyList = historyDao.getAllHistory()
            Log.d("SecActivity", "History list size: ${historyList.size}")
            runOnUiThread {
                recyclerView.adapter = HistoryAdapter(historyList)
            }
        }
    }
}